define([
    'jquery',
    'underscore',
    'backbone',
    'text!template/mail/mail_item.html',
    'collection/mail/mail',
    'bootstrap'
], function(
    $,
    _,
    Backbone,
    ItemTemplate,
    MailCollection,
    require
){

    var App = Backbone.View.extend({
        el: '#page-mail',
        template: _.template(ItemTemplate),

        initialize: function() {
            this.render();
        },

        render: function() {
            var _this = this;

            var mailCollection = new MailCollection();
            mailCollection.fetch({
                success: function(mails) {
                    var mailsData = mails.toJSON();

                    for (var i=0; i<mailsData.length; i++) {
                        _this.$el.find('[bb-container]').append(_this.template({
                            mail_graphic: mailsData[i].mail_graphic,
                            mail_cover: mailsData[i].mail_cover,
                            name: mailsData[i].name,
                            graphic_de_waver: mailsData[i].graphic_de_waver,
                            frontend_de_waver: mailsData[i].frontend_de_waver,
                            post_time: mailsData[i].post_time
                        }));
                    }
                }
            });
        }
    });

    new App();
});
